package com.example.mumu.passwordbook.common;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.example.mumu.passwordbook.domain.IconEnum;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by lupan 2018/6/16
 *
 */
public class AccountIconRecyclerViewAdapter extends RecyclerView.Adapter<AccountIconRecyclerViewAdapter.AccountIconViewHandler>{

    private List<IconEnum> list;

    public AccountIconRecyclerViewAdapter() {
        list = new ArrayList<>();
        list.addAll(Arrays.asList(IconEnum.values()));
    }

    public class AccountIconViewHandler extends RecyclerView.ViewHolder{

        private ImageView icon;

        public AccountIconViewHandler(@NonNull View itemView) {
            super(itemView);
            icon = (ImageView) itemView;
        }

        public ImageView getIcon() {
            return icon;
        }
    }

    @NonNull
    @Override
    public AccountIconViewHandler onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ImageView imageView = new ImageView(parent.getContext());
        imageView.setLayoutParams(new ViewGroup.LayoutParams(100,100));
        return new AccountIconViewHandler(imageView);
    }

    @Override
    public void onBindViewHolder(@NonNull AccountIconViewHandler holder, int position) {
           holder.getIcon().setImageResource(list.get(position).getResource());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }



}
